import baseUserHttp from './BaseUserHttp'

const getSMSCode = async (mobile) => {
    if(!mobile){
        throw new Error('请传入手机号码！');
        return;
    }
    const url=`/user/smscode/${mobile}`
    return await baseUserHttp.get(url,{})
}
const login = async (mobile,smscode) => {
    const url=`/user/login`
    return await baseUserHttp.post(url,{
        mobile,
        smscode
    })
}
const logout = async () => {
    const url = `/user/logout`
    return await baseUserHttp.get(url,{})
}

const updateUsername=async (username)=>{
    const url=`/user/update/username`
    return await baseUserHttp.put(url,{
        username
    })
}
const updateAccessToken = async () => {
	await baseUserHttp.update_access_token();
}
const createAddress = (data) => {
	const path = "/address/create"
	return baseUserHttp.post(path, data)
}
const getAddressList = (page=1, size=10) => {
	const path = "/address/list?page=" + page + "&size=" + size;
	return baseUserHttp.get(path);
}
const updateAddress = (data) => {
	const path = "/address/update"
	return baseUserHttp.put(path, data)
}
const deleteAddress = (address_id) => {
	const path = "/address/delete"
	return baseUserHttp.delete(path, {id: address_id})
}

export default {
    getSMSCode,
    login,
    logout,
    updateUsername,
    updateAccessToken,
    createAddress,
    getAddressList,
    updateAddress,
    deleteAddress
}